import React, {useRef} from 'react';
import {Divider, Popconfirm} from 'antd';
import {PageHeaderWrapper} from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import {getEndHolidayList} from '../service';
import moment from 'moment';
import { BPMStatusEnum } from '@/utils/constant'

const TableList = () => {
  const actionRef = useRef();
  const columns = [
    {
      title: '申请人工号',
      hideInSearch: true,
      dataIndex: 'code',
    },
    {
      title: '申请人姓名',
      dataIndex: 'userName',
    },
    {
      title: '公司',
      dataIndex: 'orgName',
    },
    {
      title: '部门',
      dataIndex: 'unitName',
    },
    {
      title: '岗位',
      dataIndex: 'jobName',
    },
    {
      title: '开始销假日期',
      dataIndex: 'beginGmtCancel',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : '';
      },
    },
    {
      title: '结束销假日期',
      dataIndex: 'endGmtCancel',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? moment(text).format('YYYY-MM-DD') : '';
      },
    },
    {
      title: '销假时长',
      dataIndex: 'longCancel',
      hideInSearch: true,
      render: (text) => {
        return text !== '-' ? text + `小时` : '';
      }
    },
    {
      title: '销假说明',
      dataIndex: 'remarkCancel',
      hideInSearch: true,
      ellipsis:true,
      width: 200
    },
    {
      title: '审批状态',
      dataIndex: 'status',
      hideInSearch: true,
      valueEnum: BPMStatusEnum
    },
    {
      title: '操作',
      dataIndex: 'option',
      valueType: 'option',
      align:'center',
      render: (item, record) => (
        <>
          {(record.status !== 0 && record.checkUrl) && <><a onClick={() => window.open(record.checkUrl)}>审批详情</a></>}
        </>
      ),
    }
  ];

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        rowKey="id"
        request={(params) => getEndHolidayList(params)}
        columns={columns}
      />
    </PageHeaderWrapper>
  )
};

export default (TableList);
